package com.dingwen.treasure.business.component.listener;

import cn.hutool.json.JSONUtil;
import com.dingwen.treasure.business.component.event.CreateOrderEvent2;
import com.dingwen.treasure.business.model.dto.OrderDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 库存监听器: 创建订单事件 --> 1: 库存业务逻辑实现 </br>
 * <p>{@code @Order 越小越优先执行}</p>
 *
 * @author dingwen
 * @date 2022/04/23
 */
@Component
@Order(-1)
@Slf4j
public class StokeListener2 {

    /**
     * 应用程序事件
     *
     * @param event 事件
     */
    @Async
    @EventListener(CreateOrderEvent2.class)
    public void onApplicationEvent(CreateOrderEvent2 event) {
        // 订单事件对象DTO
        OrderDto orderDTO = event.getOrderDTO();
        log.info("创建订单事件，库存业务逻辑执行，数据对象：\n{}", JSONUtil.toJsonPrettyStr(orderDTO));
    }

}
